package com.hut.oa.model.bean;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import net.minidev.json.annotate.JsonIgnore;

/**
 * 通讯录
 * @author zdd
 *
 */
@Entity
@Table(name="address_book")
public class AddressBook {
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="ab_id")
	private Long id;//通讯录id
	
	@ManyToOne(fetch=FetchType.EAGER)
	@JsonIgnore
	@JoinColumn(name="ab_dir_id")
	private AddressDir dir;//目录id
	
	@Column(name="ab_type")
	private Long type=0l;//类型id
	
	@Column(name="ab_permission")
	private String permission="我的通讯录";//权限
	
	@Column(name="ab_username")
	private String username;//联系人姓名
	
	@Column(name="ab_sex")
	private Integer sex;//性别
	
	@Column(name="ab_tel")
	private String tel;//手机号码
	
	
	@Column(name="ab_fax")
	private String fax;//传真
	
	@Column(name="ab_email")
	private String email;//邮箱
	
	@Column(name="ab_addr")
	private String addr;//地址
	
	@Column(name="ab_photo")
	private String photo;//头像
	
	@Column(name="ab_remark")
	private String remark;//备注
	
	@Column(name="ab_createtime")
	private Date createtime;//创建时间
	
	@ManyToOne()
	@JsonIgnore
	@JoinColumn(name="ab_user_id")	
	private User user;//用户id
	
	@JsonIgnore
	@ManyToMany(cascade=CascadeType.REFRESH,fetch = FetchType.LAZY)
	@JoinTable(name = "address_user",
    joinColumns = {
            @JoinColumn(name = "au_address_id")
    }, inverseJoinColumns = {
    @JoinColumn(name = "au_user_id")
})
	private List<User> addressuser;
	
	
	public AddressBook() {}
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public AddressDir getDir() {
		return dir;
	}
	public void setDir(AddressDir dir) {
		this.dir = dir;
	}
	public Long getType() {
		return type;
	}

	public void setType(Long type) {
		this.type = type;
	}

	public String getPermission() {
		return permission;
	}

	public void setPermission(String permission) {
		this.permission = permission;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	

	public Integer getSex() {
		return sex;
	}
	public void setSex(Integer sex) {
		this.sex = sex;
	}
	public String getTel() {
		return tel;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}



	public String getFax() {
		return fax;
	}

	public void setFax(String fax) {
		this.fax = fax;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getAddr() {
		return addr;
	}

	public void setAddr(String addr) {
		this.addr = addr;
	}

	public String getPhoto() {
		return photo;
	}

	public void setPhoto(String photo) {
		this.photo = photo;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public Date getCreatetime() {
		return createtime;
	}
	public void setCreatetime(Date createtime) {
		this.createtime = createtime;
	}
	public List<User> getAddressuser() {
		return addressuser;
	}
	public void setAddressuser(List<User> addressuser) {
		this.addressuser = addressuser;
	}
	@Override
	public String toString() {
		return "AddressBook [id=" + id + ", type=" + type + ", permission=" + permission
				+ ", username=" + username + ", sex=" + sex + ", tel=" + tel + ", fax=" + fax
				+ ", email=" + email + ", addr=" + addr + ", photo=" + photo + ", remark=" + remark + "]";
	}
	
}
